<?php
use yii\helpers\Url;
/* @var $this \yii\web\View */
/* @var $content string */
/* @var \common\models\User $info */

$this->title = '基本信息'
?>
<section class="app-container app-form app-send">
    
    <!-- form -->
    <div class="app-form-group">
        <label for="">手机号：</label>
        <input type="text" class="app-form-control" placeholder="手机号码" value="<?= Yii::$app->user->identity->mobile ?>" readonly>
    </div>
    
    <div class="app-form-group">
        <label for="">姓名：</label>
        <input type="text" class="app-form-control" name="realname" placeholder="请输入姓名" value="<?= $info->realname ?>">
    </div>
    <div class="app-form-group">
        <label for="">性别:</label>
        <select name="sex" id="sex" class="app-form-control">
            <option value="1" <?php if($info->sex == 1) { echo 'selected'; } ?>>男</option>
            <option value="2" <?php if($info->sex == 2) { echo 'selected'; } ?>>女</option>
        </select>
    </div>

    <div class="app-form-group">
        <label for="">生日：</label>
        <input type="date" class="app-form-control" name="birthday" placeholder="请选择出生日期" value="<?= $info->birthday ?>">
    </div>
    
    <div class="app-form-group">
        <label for="">年龄：</label>
        <input type="text" class="app-form-control" name="age" value="<?= $info->age ?>" placeholder="请输入年龄">
    </div>

    <div class="app-form-group">
        <label for="">身份证：</label>
        <input type="text" class="app-form-control" name="idcard" placeholder="请输入身份证号" value="<?= $info->idcard ?>">
    </div>

    <div class="app-form-group">
        <label for="">地址：</label>
        <input type="text" class="app-form-control" name="address" placeholder="请输入详细地址" value="<?= $info->address ?>">
    </div>
    <div class="app-form-button">
        <input type="hidden" name="_csrf-frontend" value="<?= Yii::$app->request->csrfToken ?>">
        <button class="app-form-control app-btn-submit" id="submit">保存</button>
    </div>
    
</section>
<script src="/js/jquery.min.js"></script>
<script src="/js/layer_mobile/layer.js"></script>
<script>
    $(function(){
        var _csrf = '<?= Yii::$app->request->csrfToken ?>';
        var submitUrl = '<?= Url::toRoute(['member/info']) ?>'
        $('#submit').click(function(){
            var realname = $('input[name="realname"]').val();
            var sex = $("#sex").val();
            var age = $("input[name='age']").val();
            var birthday = $("input[name='birthday']").val();
            var idcard = $("input[name='idcard']").val();
            var address = $("input[name='address']").val();
            var request = {
                realname: realname,sex:sex,age:age,birthday:birthday,idcard:idcard,address:address,"_csrf-frontend":_csrf
            }
            $.post(submitUrl, request, function(result){
                if( result.success == true ){
                    layer.open({
                        shadeClose: false,
                        content: '保存成功',
                        btn: '确定',
                        end: function(){
                            window.history.back();
                        }
                    });
                }else{
                    layer.open({
                        shadeClose: false,
                        content: result.msg,
                        btn: '确定',
                    });
                }
            }, 'json')
            
        })
    });
</script>
